package com.kitty.game.role.model;

import com.kitty.common.db.BaseEntityGame;
import com.kitty.common.model.Reason;
import lombok.Getter;
import lombok.Setter;
import org.nutz.dao.entity.annotation.ColDefine;
import org.nutz.dao.entity.annotation.Column;
import org.nutz.dao.entity.annotation.Name;
import org.nutz.dao.entity.annotation.Table;

import java.util.Date;

/**
 * 玩家账号表实体类
 */
@Table("t_account")
@Setter
@Getter
public class Account extends BaseEntityGame<String> {
    @Name
    private String id;
    @Column
    private String username;
    @Column
    private String mobile;
    @Column
    private String channelCode;
    @Column
    private Date createTime;
    @Column
    private String ip;
    @Column
    @ColDefine(width = 512)
    private String deviceInfo;
    @Column
    private int isStop;
    @Column
    @ColDefine(width = 512)
    private String pwd;
    @Column
    private short privilege=0;//帐号权限
    @Column
    private int gold;//元宝
    @Column
    private int isuse;

    public Account(String id, String username, String channelCode,short privilege) {
        this.id = id;
        this.username = username;
        this.channelCode = channelCode;
        this.privilege = privilege;
    }
    public Account() {
    }

    public void addGold(int gold, Reason reason) {
        if (gold < 0) {
            throw new IllegalArgumentException("增加元宝不能为负数");
        }

        int before = this.gold;
        this.gold += gold;

    }

    public Boolean costGold(int gold, Reason reason) {
        if (gold < 0) {
            return false;
        }

        int before = this.gold;
        if (before < gold) {
            return false;
            //throw new IllegalArgumentException("元宝不足#R"+gold);
        }
        this.gold -= gold;
        return true;
    }

}
